const app = getApp()
Page({
  data: {
    loading: true,
    page:0,
    icons:[],
    stores: [],
  },
  //监听页面显示
  onShow:function (){
    this.getCate();
  },
  //下拉刷新
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    setTimeout(function () {
      wx.hideNavigationBarLoading();
      wx.stopPullDownRefresh();
    },1500);
    this.setData({
      loading: true,
      page: 0,
      stores: []
    });
    this.getCate();
  },
  //下拉
  onReachBottom: function () {
    this.setData({
      loading: true,
    });
    this.getApiStroe();
  },
  //行业分类
  getCate: function () {
    var param = {
      signkey: app.util().getRandom(12),
      cate_id:0,
      lists:0
    }
    app.api().Get('api/v4/allwin/store/category', param,(result)=>{
      if (result.code == 200) {
        this.setData({
          icons:result.data,
          loading: true,
          page: 0,
          stores:[]
        })
        this.getApiStroe();
      }
    })
  },
  /**
   * 获取店铺
   */
  getApiStroe:function(){
    if (this.data.loading) {
      var param =  {
        page: this.data.page+1,
        cate_id:0,
        cate_sid:0,
      }
      app.api().Get('api/v4/allwin/store/lists',param,(result) => {
        if (result.code == 200) {
          var stores = this.data.stores;
          for (let i in result.data) {
            stores.push(result.data[i]);
          }
          this.setData({
            stores: stores,
            page: param.page,
          });
        }
        this.setData({
          loading: false
        })
      })
    }
  },
  //搜索
  onSearch: function (e) {
    wx.navigateTo({
      url: '../search?keyword='+e.detail,
    })
  },
  //分享按钮
  onShareAppMessage: function () {
    var config = app.globalData.appConfig;
     return {
       title: config.store_share_text,
       imageUrl:config.store_share_img,
       path: '/pages/store/index?ucode=' + app.globalData.loginuser.ucode
     }
  },
});